const mongoose = require('mongoose');

const DB_URL = 'mongodb+srv://root:admin@cluster0-tewqq.mongodb.net/test?retryWrites=true&w=majority';
/**
 * 连接
 */
mongoose.connect(DB_URL, {
    useUnifiedTopology: true,
    useNewUrlParser: true,
    useFindAndModify: true
}, () => console.log('mongoose连接成功了！'))

/**
  * 连接成功
  */
mongoose.connection.on('connected', () => {
    console.log('Mongoose connection open to ' + DB_URL);
});

/**
 * 连接异常
 */
mongoose.connection.on('error', (err) => {
    console.log('Mongoose connection error: ' + err);
});

/**
 * 连接断开
 */
mongoose.connection.on('disconnected', function () {
    console.log('Mongoose connection disconnected');
});

module.exports = mongoose;
